package net.tycmc.cty.ctyms.timejob.common;

import java.util.Map;

import net.tycmc.bulb.common.dao.IBaseDAO;

public class GetTimQuery {
	private static GetTimQuery getTimQuery = null;
	IBaseDAO baseDAO;
	
	private GetTimQuery(IBaseDAO baseDAO){
		this.baseDAO = baseDAO;
	}
	
	public static GetTimQuery getInstance(IBaseDAO baseDAO){
		if(getTimQuery==null){
			getTimQuery = new GetTimQuery(baseDAO);
		}
		return getTimQuery;
	}
	/**
     * 判断表是否存在
     * @param DBName，数据库名称，默认（不填）为DAO默认连接数据库
     * @param tableName，表名
     * @return
     */
    public boolean isExtTabByDB(String DBName,String tableName) {
    	String strSQL = "";
    	if("".equals(DBName)){
    		strSQL = "Select Count(1) as cnt FROM SysObjects Where Name=?";
    	}else{
    		strSQL = "Select Count(1) as cnt FROM "+DBName+".dbo.SysObjects Where Name=?";
    	}
		Map<String, Object> map = baseDAO.execQueryOne(strSQL, new Object[]{tableName});
		int ok = 0;
		try {
			ok = Integer.parseInt(map.get("cnt").toString());
		} catch (Exception e) {
		}
		if(ok>0)return true;
		return false;
	}
}
